﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.view.common.*;

    public class JewelUpdateConfig extends Object
    {
        private var _map:Dictionary;
        private static var _instance:JewelUpdateConfig;

        public function JewelUpdateConfig()
        {
            this._map = new Dictionary();
            if (_instance != null)
            {
                throw new Error("JewelUpdateConfig 单例");
            }
            this.init();
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_jewel_update.json");
            this.write(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TJewelUpdate = null;
            var _loc_3:Object = null;
            var _loc_4:Array = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TJewelUpdate();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                _loc_4 = this._map[_loc_2.color] as Array;
                if (_loc_4 == null)
                {
                    _loc_4 = [];
                    _loc_4.push(_loc_2);
                    this._map[_loc_2.color] = _loc_4;
                    continue;
                }
                _loc_4.push(_loc_2);
            }
            return;
        }// end function

        public function getMaxLevelByGemColor(param1:int) : int
        {
            var _loc_3:int = 0;
            var _loc_4:TJewelUpdate = null;
            var _loc_2:* = this._map[param1] as Array;
            if (_loc_2)
            {
                for each (_loc_4 in _loc_2)
                {
                    
                    if (_loc_4.level > _loc_3)
                    {
                        _loc_3 = _loc_4.level;
                    }
                }
            }
            return _loc_3;
        }// end function

        public function getGemAttr(param1:int, param2:int, param3:String) : int
        {
            var _loc_5:TJewelUpdate = null;
            var _loc_4:* = this._map[param1] as Array;
            if (_loc_4)
            {
                for each (_loc_5 in _loc_4)
                {
                    
                    if (_loc_5.level == param2)
                    {
                        return _loc_5[param3];
                    }
                }
            }
            return 0;
        }// end function

        public function getInfoByColorAndLevel(param1:int, param2:int) : TJewelUpdate
        {
            var _loc_4:TJewelUpdate = null;
            var _loc_3:* = this._map[param1] as Array;
            if (_loc_3)
            {
                for each (_loc_4 in _loc_3)
                {
                    
                    if (_loc_4.level == param2)
                    {
                        return _loc_4;
                    }
                }
            }
            return null;
        }// end function

        public static function get instance() : JewelUpdateConfig
        {
            if (_instance == null)
            {
                _instance = new JewelUpdateConfig;
            }
            return _instance;
        }// end function

    }
}
